package com.example.expandablelistview.menu;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.PopupMenu;

import com.example.expandablelistview.R;

public class PopupMenuEx extends Activity {
	Button mBtn;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.popupmenuex);
		mBtn = (Button) findViewById(R.id.popupmenuBtn01);
	}

	public void mOnClick(View v) {
		PopupMenu popup = new PopupMenu(this, v);
		/*
		 * MenuInflater infaltor = popup.getMenuInflater(); Menu menu =
		 * popup.getMenu(); infaltor.inflate(R.menu.popupmenutestmenu, menu);
		 */
		popup.inflate(R.menu.popupmenutestmenu);
		popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
			public boolean onMenuItemClick(MenuItem item) {
				switch (item.getItemId()) {
					case R.id.popup_red:
						mBtn.setBackgroundColor(Color.RED);
						break;
					case R.id.popup_green:
						mBtn.setBackgroundColor(Color.GREEN);
						break;
					case R.id.popup_blue:
						mBtn.setBackgroundColor(Color.BLUE);
						break;
					case R.id.popup_black:
						mBtn.setTextColor(Color.BLACK);
						break;
					case R.id.popup_white:
						mBtn.setTextColor(Color.WHITE);
						break;
					case R.id.popup_gray:
						mBtn.setTextColor(Color.GRAY);
						break;
				}
				return false;
			}
		});
		popup.show();
	}

}
